package servlet;

import hibernate.DictInfo;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.DictInfoDAO;



public class DictInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public DictInfoServlet() {
        super();
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();   
		@SuppressWarnings("unchecked")
        List getInfo;
		DictInfoDAO dictdao = new DictInfoDAO();
		getInfo = dictdao.getAllDepartment();
		String s = "{department:[";
        for(int i=0;i<getInfo.size();i++)
        {     	
        	DictInfo info = (DictInfo)getInfo.get(i);    
			s = s + "{name:" + "'" + info.getName() + "'},";
        }
        if(!"{department:[".equals(s))
        {
        	s = s.substring(0, s.length()-1);
        }
        
        s = s + "]}";
        out.println(s);
        out.flush();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
